/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package other;

import B3D_Elements.B3D_Element;
import B3D_Elements.B3D_Filters.B3D_BasicSSAO;
import B3D_Elements.B3D_Filters.B3D_Bloom;
import B3D_Elements.B3D_Filters.B3D_Cartoon;
import B3D_Elements.B3D_Filters.B3D_ColorScale;
import B3D_Elements.B3D_Filters.B3D_Crosshatch;
import B3D_Elements.B3D_Filters.B3D_DepthOfField;
import B3D_Elements.B3D_Filters.B3D_Filter;
import B3D_Elements.B3D_Filters.B3D_Fog;
import B3D_Elements.B3D_Filters.B3D_FrostedGlass;
import B3D_Elements.B3D_Filters.B3D_LightScattering;
import B3D_Elements.B3D_Filters.B3D_OldFilm;
import B3D_Elements.B3D_Filters.B3D_Posterization;
import B3D_Elements.B3D_Filters.B3D_SSAO;
import B3D_Elements.B3D_Filters.B3D_Shadows.B3D_DLShadow;
import B3D_Elements.B3D_Filters.B3D_Shadows.B3D_PLShadow;
import B3D_Elements.B3D_Filters.B3D_Shadows.B3D_SLShadow;
import B3D_Elements.B3D_Filters.B3D_Water;
import B3D_Elements.B3D_Lights.B3D_AmbientLight;
import B3D_Elements.B3D_Lights.B3D_DirectionalLight;
import B3D_Elements.B3D_Lights.B3D_Light;
import B3D_Elements.B3D_Lights.B3D_PointLight;
import B3D_Elements.B3D_Lights.B3D_SpotLight;
import B3D_Elements.B3D_Physics.B3D_CShapes.B3D_BoxShape;
import B3D_Elements.B3D_Physics.B3D_CShapes.B3D_CShape;
import B3D_Elements.B3D_Physics.B3D_CShapes.B3D_CapsuleShape;
import B3D_Elements.B3D_Physics.B3D_CShapes.B3D_ConeShape;
import B3D_Elements.B3D_Physics.B3D_CShapes.B3D_CylinderShape;
import B3D_Elements.B3D_Physics.B3D_CShapes.B3D_DynamicMeshShape;
import B3D_Elements.B3D_Physics.B3D_CShapes.B3D_StaticMeshShape;
import B3D_Elements.B3D_Physics.B3D_Physics;
import B3D_Elements.B3D_Spatials.B3D_Geometrys.B3D_Box;
import B3D_Elements.B3D_Spatials.B3D_Geometrys.B3D_Cylinder;
import B3D_Elements.B3D_Spatials.B3D_Geometrys.B3D_ParticleEffect;
import B3D_Elements.B3D_Spatials.B3D_Geometrys.B3D_MultipleTextureSkyBox;
import B3D_Elements.B3D_Spatials.B3D_Geometrys.B3D_SingleTextureSkyBox;
import B3D_Elements.B3D_Spatials.B3D_Geometrys.B3D_Sphere;
import B3D_Elements.B3D_Spatials.B3D_Geometrys.B3D_Torus;
import B3D_Elements.B3D_Spatials.B3D_Model;
import B3D_Elements.B3D_Spatials.B3D_Node;
import B3D_Elements.B3D_Spatials.B3D_Spatial;
import B3D_Elements.Others.B3D_Material;
import B3D_Elements.Others.B3D_MaterialPropertyList;
import B3D_Elements.Others.B3D_MotionEvent;
import B3D_Elements.Others.B3D_MotionPath;
import com.jme3.animation.LoopMode;
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.ConeCollisionShape;
import com.jme3.bullet.collision.shapes.CylinderCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.cinematic.MotionPath;
import com.jme3.cinematic.events.MotionEvent;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.light.Light;
import com.jme3.light.PointLight;
import com.jme3.light.SpotLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Spline;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.math.Vector4f;
import com.jme3.post.Filter;
import com.jme3.post.filters.BloomFilter;
import com.jme3.post.filters.CartoonEdgeFilter;
import com.jme3.post.filters.CrossHatchFilter;
import com.jme3.post.filters.DepthOfFieldFilter;
import com.jme3.post.filters.FogFilter;
import com.jme3.post.filters.LightScatteringFilter;
import com.jme3.post.filters.PosterizationFilter;
import com.jme3.post.ssao.SSAOFilter;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Cylinder;
import com.jme3.scene.shape.Sphere;
import com.jme3.scene.shape.Torus;
import com.jme3.shadow.DirectionalLightShadowFilter;
import static com.jme3.shadow.EdgeFilteringMode.Bilinear;
import static com.jme3.shadow.EdgeFilteringMode.Dither;
import static com.jme3.shadow.EdgeFilteringMode.Nearest;
import static com.jme3.shadow.EdgeFilteringMode.PCF4;
import static com.jme3.shadow.EdgeFilteringMode.PCF8;
import static com.jme3.shadow.EdgeFilteringMode.PCFPOISSON;
import com.jme3.shadow.PointLightShadowFilter;
import com.jme3.shadow.SpotLightShadowFilter;
import com.jme3.util.SkyFactory;
import com.jme3.water.WaterFilter;
import com.shaderblow.filter.basicssao.BasicSSAO;
import com.shaderblow.filter.frostedglass.FrostedGlassFilter;
import com.shaderblow.filter.oldfilm.OldFilmFilter;
import com.simsilica.lemur.geom.MBox;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.UUID;

/**
 *
 * @author David
 */
public class ElementToObjectConverter
{

    public static Object converToObject(B3D_Element element)
    {
        Object object = null;
        if (element instanceof B3D_Filter)
        {
            object = convertFilter((B3D_Filter) element);
        } else if (element instanceof B3D_Light)
        {
            object = convertLight((B3D_Light) element);
        } else if (element instanceof B3D_Spatial)
        {
            object = convertSpatial((B3D_Spatial) element);
        } else if (element instanceof B3D_MotionEvent)
        {
            object = convertMotionEvent((B3D_MotionEvent) element);
        } else if (element instanceof B3D_Material)
        {
            object = convertMaterial((B3D_Material) element);
        }
        return object;
    }

    public static Filter convertFilter(B3D_Filter b3D_Filter)
    {
        if (b3D_Filter instanceof B3D_BasicSSAO)
        {
            return convertBasicSSAO((B3D_BasicSSAO) b3D_Filter);
        }
        if (b3D_Filter instanceof B3D_Bloom)
        {
            return convertBloom((B3D_Bloom) b3D_Filter);
        } else if (b3D_Filter instanceof B3D_Cartoon)
        {
            return convertCartoon((B3D_Cartoon) b3D_Filter);
        } else if (b3D_Filter instanceof B3D_ColorScale)
        {
            return convertColorScale((B3D_ColorScale) b3D_Filter);
        } else if (b3D_Filter instanceof B3D_Crosshatch)
        {
            return convertCrosshatch((B3D_Crosshatch) b3D_Filter);
        } else if (b3D_Filter instanceof B3D_DepthOfField)
        {
            return convertDOF((B3D_DepthOfField) b3D_Filter);
        } else if (b3D_Filter instanceof B3D_LightScattering)
        {
            return convertLightScattering((B3D_LightScattering) b3D_Filter);
        } else if (b3D_Filter instanceof B3D_Fog)
        {
            return convertFog((B3D_Fog) b3D_Filter);
        } else if (b3D_Filter instanceof B3D_FrostedGlass)
        {
            return convertFrostedGlass((B3D_FrostedGlass) b3D_Filter);
        } else if (b3D_Filter instanceof B3D_OldFilm)
        {
            return convertOldFilm((B3D_OldFilm) b3D_Filter);
        } else if (b3D_Filter instanceof B3D_Posterization)
        {
            return convertPosterization((B3D_Posterization) b3D_Filter);
        } else if (b3D_Filter instanceof B3D_SSAO)
        {
            return convertSSAO((B3D_SSAO) b3D_Filter);
        } else if (b3D_Filter instanceof B3D_Water)
        {
            return convertWater((B3D_Water) b3D_Filter);
        } else if (b3D_Filter instanceof B3D_DLShadow)
        {
            return convertDirectionalLightShadow((B3D_DLShadow) b3D_Filter);
        } else if (b3D_Filter instanceof B3D_PLShadow)
        {
            return convertPointLightShadow((B3D_PLShadow) b3D_Filter);
        } else if (b3D_Filter instanceof B3D_SLShadow)
        {
            return convertSpotLightShadow((B3D_SLShadow) b3D_Filter);
        }
        return null;
    }

    public static DirectionalLightShadowFilter convertDirectionalLightShadow(B3D_DLShadow b3D_DLShadow)
    {
        DirectionalLightShadowFilter dlsf = new DirectionalLightShadowFilter(Wizard.getAssetManager(), b3D_DLShadow.getShadowMapSize(), 3);
        switch (b3D_DLShadow.getEdgeFilteringMode())
        {
            case Bilinear:
                dlsf.setEdgeFilteringMode(Bilinear);
                break;
            case Dither:
                dlsf.setEdgeFilteringMode(Dither);
                break;
            case Nearest:
                dlsf.setEdgeFilteringMode(Nearest);
                break;
            case PCF4:
                dlsf.setEdgeFilteringMode(PCF4);
                break;
            case PCF8:
                dlsf.setEdgeFilteringMode(PCF8);
                break;
            case PCFPOISSON:
                dlsf.setEdgeFilteringMode(PCFPOISSON);
        }
        dlsf.setEdgesThickness(b3D_DLShadow.getEdgeThickness());
        dlsf.setFlushQueues(b3D_DLShadow.isFlushQueues());
        dlsf.setShadowIntensity(b3D_DLShadow.getIntensity());
        dlsf.setName(b3D_DLShadow.getName());
        dlsf.setLight((DirectionalLight) Wizard.getElementList().getObject(b3D_DLShadow.getDirectionalLightID()));
        return dlsf;
    }

    public static SpotLightShadowFilter convertSpotLightShadow(B3D_SLShadow b3D_SLShadow)
    {
        SpotLightShadowFilter slsf = new SpotLightShadowFilter(Wizard.getAssetManager(), b3D_SLShadow.getShadowMapSize());
        switch (b3D_SLShadow.getEdgeFilteringMode())
        {
            case Bilinear:
                slsf.setEdgeFilteringMode(Bilinear);
                break;
            case Dither:
                slsf.setEdgeFilteringMode(Dither);
                break;
            case Nearest:
                slsf.setEdgeFilteringMode(Nearest);
                break;
            case PCF4:
                slsf.setEdgeFilteringMode(PCF4);
                break;
            case PCF8:
                slsf.setEdgeFilteringMode(PCF8);
                break;
            case PCFPOISSON:
                slsf.setEdgeFilteringMode(PCFPOISSON);
        }
        slsf.setEdgesThickness(b3D_SLShadow.getEdgeThickness());
        slsf.setFlushQueues(b3D_SLShadow.isFlushQueues());
        slsf.setShadowIntensity(b3D_SLShadow.getIntensity());
        slsf.setName(b3D_SLShadow.getName());
        slsf.setLight((SpotLight) Wizard.getElementList().getObject(b3D_SLShadow.getSpotLightID()));
        return slsf;
    }

    public static PointLightShadowFilter convertPointLightShadow(B3D_PLShadow b3D_PLShadow)
    {
        PointLightShadowFilter plsf = new PointLightShadowFilter(Wizard.getAssetManager(), b3D_PLShadow.getShadowMapSize());
        switch (b3D_PLShadow.getEdgeFilteringMode())
        {
            case Bilinear:
                plsf.setEdgeFilteringMode(Bilinear);
                break;
            case Dither:
                plsf.setEdgeFilteringMode(Dither);
                break;
            case Nearest:
                plsf.setEdgeFilteringMode(Nearest);
                break;
            case PCF4:
                plsf.setEdgeFilteringMode(PCF4);
                break;
            case PCF8:
                plsf.setEdgeFilteringMode(PCF8);
                break;
            case PCFPOISSON:
                plsf.setEdgeFilteringMode(PCFPOISSON);
        }
        plsf.setEdgesThickness(b3D_PLShadow.getEdgeThickness());
        plsf.setFlushQueues(b3D_PLShadow.isFlushQueues());
        plsf.setShadowIntensity(b3D_PLShadow.getIntensity());
        plsf.setName(b3D_PLShadow.getName());
        plsf.setLight((PointLight) Wizard.getElementList().getObject(b3D_PLShadow.getPointLightShadowID()));
        return plsf;
    }

    public static BasicSSAO convertBasicSSAO(B3D_BasicSSAO b3D_BasicSSAO)
    {
        BasicSSAO basicSSAO = new BasicSSAO();
        basicSSAO.setBias(b3D_BasicSSAO.getBias());
        basicSSAO.setDetailBias(b3D_BasicSSAO.getDetailBias());
        basicSSAO.setDetailIntensity(b3D_BasicSSAO.getDetailIntensity());
        basicSSAO.setDetailSampleRadius(b3D_BasicSSAO.getSampleRadius());
        basicSSAO.setDetailScale(b3D_BasicSSAO.getDetailScale());
        basicSSAO.setFalloffRate(b3D_BasicSSAO.getFalloffRate());
        basicSSAO.setFalloffStartDistance(b3D_BasicSSAO.getFalloffStartDistance());
        basicSSAO.setIntensity(b3D_BasicSSAO.getIntensity());
        basicSSAO.setSampleRadius(b3D_BasicSSAO.getSampleRadius());
        basicSSAO.setScale(b3D_BasicSSAO.getScale());
        basicSSAO.setSmoothMore(b3D_BasicSSAO.isSmoothMore());
        basicSSAO.setUseAo(b3D_BasicSSAO.isUseAO());
        basicSSAO.setUseDetailPass(b3D_BasicSSAO.isUseDetailPass());
        basicSSAO.setUseDistanceFalloff(b3D_BasicSSAO.isUseDistanceFalloff());
        basicSSAO.setUseOnlyAo(b3D_BasicSSAO.isUseOnlyAO());
        basicSSAO.setUseSmoothing(b3D_BasicSSAO.isUseSmoothing());
        return basicSSAO;
    }

    public static BloomFilter convertBloom(B3D_Bloom b3D_Bloom)
    {
        BloomFilter bloomFilter = new BloomFilter();
        bloomFilter.setName(b3D_Bloom.getName());
        bloomFilter.setBloomIntensity(b3D_Bloom.getIntensity());
        bloomFilter.setBlurScale(b3D_Bloom.getBlurScale());
        bloomFilter.setDownSamplingFactor(b3D_Bloom.getDownSamplingFactor());
        bloomFilter.setExposureCutOff(b3D_Bloom.getExposureCutOff());
        bloomFilter.setExposurePower(b3D_Bloom.getExposurePower());
        return bloomFilter;
    }

    public static CartoonEdgeFilter convertCartoon(B3D_Cartoon b3D_Cartoon)
    {
        CartoonEdgeFilter cartoonEdgeFilter = new CartoonEdgeFilter();
        cartoonEdgeFilter.setName(b3D_Cartoon.getName());
        cartoonEdgeFilter.setDepthSensitivity(b3D_Cartoon.getDepthSensivity());
        cartoonEdgeFilter.setDepthThreshold(b3D_Cartoon.getDepthTreshold());
        cartoonEdgeFilter.setEdgeColor(b3D_Cartoon.getColor());
        cartoonEdgeFilter.setEdgeIntensity(b3D_Cartoon.getEdgeIntensity());
        cartoonEdgeFilter.setEdgeWidth(b3D_Cartoon.getEdgeWidth());
        cartoonEdgeFilter.setNormalSensitivity(b3D_Cartoon.getNormalSensivity());
        cartoonEdgeFilter.setNormalThreshold(b3D_Cartoon.getNormalTreshold());
        return cartoonEdgeFilter;
    }

    public static ColorScaleFilterWithGetters convertColorScale(B3D_ColorScale b3D_ColorScale)
    {
        ColorScaleFilterWithGetters colorScaleFilter = new ColorScaleFilterWithGetters(b3D_ColorScale.getColor(), b3D_ColorScale.getColorDensity());
        colorScaleFilter.setMultiply(b3D_ColorScale.isMultiply());
        colorScaleFilter.setOverlay(b3D_ColorScale.isOverlay());
        return colorScaleFilter;
    }

    public static CrossHatchFilter convertCrosshatch(B3D_Crosshatch b3D_Crosshatch)
    {
        CrossHatchFilter crossHatchFilter = new CrossHatchFilter(b3D_Crosshatch.getLineColor(), b3D_Crosshatch.getPaperColor());
        crossHatchFilter.setName(b3D_Crosshatch.getName());
        crossHatchFilter.setColorInfluenceLine(b3D_Crosshatch.getColorInfluenceLine());
        crossHatchFilter.setColorInfluencePaper(b3D_Crosshatch.getColorInfluencePaper());
        crossHatchFilter.setFillValue(b3D_Crosshatch.getFillValue());
        crossHatchFilter.setLineDistance(b3D_Crosshatch.getLineDistance());
        crossHatchFilter.setLineThickness(b3D_Crosshatch.getLineThickness());
        crossHatchFilter.setLuminanceLevels(
                b3D_Crosshatch.getLuminanceLevels()[0],
                b3D_Crosshatch.getLuminanceLevels()[1],
                b3D_Crosshatch.getLuminanceLevels()[2],
                b3D_Crosshatch.getLuminanceLevels()[3],
                b3D_Crosshatch.getLuminanceLevels()[4]);
        return crossHatchFilter;
    }

    public static DepthOfFieldFilter convertDOF(B3D_DepthOfField b3D_DepthOfField)
    {
        DepthOfFieldFilter depthOfFieldFilter = new DepthOfFieldFilter();
        depthOfFieldFilter.setName(b3D_DepthOfField.getName());
        depthOfFieldFilter.setFocusDistance(b3D_DepthOfField.getFocusDistance());
        depthOfFieldFilter.setFocusRange(b3D_DepthOfField.getFocusRange());
        depthOfFieldFilter.setBlurScale(b3D_DepthOfField.getBlurScale());
        return depthOfFieldFilter;
    }

    public static LightScatteringFilter convertLightScattering(B3D_LightScattering b3D_LightScattering)
    {
        LightScatteringFilter lightScatteringFilter = new LightScatteringFilter(b3D_LightScattering.getPosition());
        lightScatteringFilter.setName(b3D_LightScattering.getName());
        lightScatteringFilter.setBlurStart(b3D_LightScattering.getBlurStart());
        lightScatteringFilter.setBlurWidth(b3D_LightScattering.getBlurWidth());
        lightScatteringFilter.setLightDensity(b3D_LightScattering.getDensity());
        lightScatteringFilter.setNbSamples(b3D_LightScattering.getSamples());
        return lightScatteringFilter;
    }

    public static FogFilter convertFog(B3D_Fog b3D_Fog)
    {
        FogFilter fogFilter = new FogFilter(b3D_Fog.getColor(), b3D_Fog.getDensity(), b3D_Fog.getDistance());
        fogFilter.setName(b3D_Fog.getName());
        return fogFilter;
    }

    public static FrostedGlassFilter convertFrostedGlass(B3D_FrostedGlass b3D_FrostedGlass)
    {
        FrostedGlassFilter frostedGlassFilter = new FrostedGlassFilter();
        frostedGlassFilter.setRandomFactor(b3D_FrostedGlass.getRandomFactor());
        frostedGlassFilter.setRandomScale(b3D_FrostedGlass.getRandomScale());
        return frostedGlassFilter;
    }

    public static OldFilmFilter convertOldFilm(B3D_OldFilm b3D_OldFilm)
    {
        return new OldFilmFilter(
                b3D_OldFilm.getColor(),
                b3D_OldFilm.getColorDensity(),
                b3D_OldFilm.getNoiseDensity(),
                b3D_OldFilm.getScratchDensity(),
                b3D_OldFilm.getVignetteValue());
    }

    public static PosterizationFilter convertPosterization(B3D_Posterization b3D_Posterization)
    {
        PosterizationFilter posterizationFilter = new PosterizationFilter(b3D_Posterization.getNumColors(), b3D_Posterization.getGamma());
        posterizationFilter.setName(b3D_Posterization.getName());
        posterizationFilter.setStrength(b3D_Posterization.getStrength());
        return posterizationFilter;
    }

    public static SSAOFilter convertSSAO(B3D_SSAO b3D_SSAO)
    {
        SSAOFilter sSAOFilter = new SSAOFilter(b3D_SSAO.getSampleRadius(), b3D_SSAO.getIntensity(), b3D_SSAO.getScale(), b3D_SSAO.getBias());
        sSAOFilter.setName(b3D_SSAO.getName());
        return sSAOFilter;
    }

    public static WaterFilter convertWater(B3D_Water b3D_Water)
    {
        WaterFilter waterFilter = new WaterFilter();
        waterFilter.setName(b3D_Water.getName());
        waterFilter.setCausticsIntensity(b3D_Water.getCausistsIntensity());
        waterFilter.setColorExtinction(b3D_Water.getColorExtinction());
        waterFilter.setDeepWaterColor(b3D_Water.getDeepWaterColor());
        waterFilter.setFoamExistence(b3D_Water.getFoamExistence());
        waterFilter.setFoamHardness(b3D_Water.getFoamHardness());
        waterFilter.setFoamIntensity(b3D_Water.getFoamIntensity());
        waterFilter.setLightColor(b3D_Water.getLightColor());
        waterFilter.setLightDirection(b3D_Water.getLightDirection());
        waterFilter.setMaxAmplitude(b3D_Water.getMaxAmplitude());
        waterFilter.setNormalScale(b3D_Water.getNormalScale());
        waterFilter.setReflectionDisplace(b3D_Water.getReflectionDisplace());
        waterFilter.setReflectionMapSize(b3D_Water.getResolution());
        waterFilter.setRefractionStrength(b3D_Water.getRefractionStrength());
        waterFilter.setShininess(b3D_Water.getShininess());
        waterFilter.setShoreHardness(b3D_Water.getShoreHardness());
        waterFilter.setSpeed(b3D_Water.getSpeed());
        waterFilter.setSunScale(b3D_Water.getSunScale());
        waterFilter.setUnderWaterFogDistance(b3D_Water.getUnderWaterFogDistance());
        waterFilter.setUseCaustics(b3D_Water.isUseCausists());
        waterFilter.setUseFoam(b3D_Water.isUseFoam());
        waterFilter.setUseHQShoreline(b3D_Water.isUseHQShoreLine());
        waterFilter.setUseRefraction(b3D_Water.isUseRefraction());
        waterFilter.setUseRipples(b3D_Water.isUseRipples());
        waterFilter.setUseSpecular(b3D_Water.isUseSpecular());
        waterFilter.setWaterColor(b3D_Water.getColor());
        waterFilter.setWaterHeight(b3D_Water.getHeight());
        waterFilter.setWaterTransparency(b3D_Water.getTransparency());
        waterFilter.setWaveScale(b3D_Water.getWaveScale());
        waterFilter.setWindDirection(b3D_Water.getWindDirection());
        return waterFilter;
    }

    public static Light convertLight(B3D_Light b3D_Light)
    {
        if (b3D_Light instanceof B3D_DirectionalLight)
        {
            return convertDirectionalLight((B3D_DirectionalLight) b3D_Light);
        } else if (b3D_Light instanceof B3D_AmbientLight)
        {
            return convertAmbientLight((B3D_AmbientLight) b3D_Light);
        } else if (b3D_Light instanceof B3D_PointLight)
        {
            return convertPointLight((B3D_PointLight) b3D_Light);
        } else if (b3D_Light instanceof B3D_SpotLight)
        {
            return convertSpotLight((B3D_SpotLight) b3D_Light);
        }
        return null;
    }

    public static DirectionalLight convertDirectionalLight(B3D_DirectionalLight b3D_DirectionalLight)
    {
        DirectionalLight directionalLight = new DirectionalLight();
        directionalLight.setName(b3D_DirectionalLight.getName());
        directionalLight.setColor(b3D_DirectionalLight.getColor());
        directionalLight.setDirection(b3D_DirectionalLight.getDirection());
        return directionalLight;
    }

    public static AmbientLight convertAmbientLight(B3D_AmbientLight b3D_AmbientLight)
    {
        AmbientLight ambientLight = new AmbientLight();
        ambientLight.setName(b3D_AmbientLight.getName());
        ambientLight.setColor(b3D_AmbientLight.getColor());
        return ambientLight;
    }

    public static PointLight convertPointLight(B3D_PointLight b3D_PointLight)
    {
        PointLight pointLight = new PointLight();
        pointLight.setName(b3D_PointLight.getName());
        pointLight.setColor(b3D_PointLight.getColor());
        pointLight.setPosition(b3D_PointLight.getPosition());
        pointLight.setRadius(b3D_PointLight.getRadius());
        return pointLight;
    }

    public static SpotLight convertSpotLight(B3D_SpotLight b3D_SpotLight)
    {
        SpotLight spotLight = new SpotLight();
        spotLight.setName(b3D_SpotLight.getName());
        spotLight.setColor(b3D_SpotLight.getColor());
        spotLight.setPosition(b3D_SpotLight.getPosition());
        spotLight.setDirection(b3D_SpotLight.getDirection());
        spotLight.setSpotInnerAngle(b3D_SpotLight.getInnerAngle());
        spotLight.setSpotOuterAngle(b3D_SpotLight.getOuterAngle());
        spotLight.setSpotRange(b3D_SpotLight.getRange());
        return spotLight;
    }

    public static Spatial convertSpatial(B3D_Spatial b3D_Spatial)
    {
        Spatial spatial = null;
        RigidBodyControl rigidBodyControl = null;
        if (b3D_Spatial instanceof B3D_Node)
        {
            spatial = convertNode((B3D_Node) b3D_Spatial);
        } else if (b3D_Spatial instanceof B3D_Model)
        {
            spatial = convertModel((B3D_Model) b3D_Spatial);
        } else if (b3D_Spatial instanceof B3D_Box)
        {
            spatial = convertBox((B3D_Box) b3D_Spatial);
            spatial.setUserData("xSlices", ((B3D_Box) b3D_Spatial).getxSlices());
            spatial.setUserData("ySlices", ((B3D_Box) b3D_Spatial).getySlices());
            spatial.setUserData("zSlices", ((B3D_Box) b3D_Spatial).getzSlices());
        } else if (b3D_Spatial instanceof B3D_Cylinder)
        {
            spatial = convertCylinder((B3D_Cylinder) b3D_Spatial);
        } else if (b3D_Spatial instanceof B3D_ParticleEffect)
        {
            ParticleEmitter particleEmitter = convertParticleEmitter((B3D_ParticleEffect) b3D_Spatial);
            particleEmitter.setMaterial(new Material(Wizard.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md"));
            particleEmitter.getMaterial().getAdditionalRenderState().setDepthWrite(((B3D_ParticleEffect) b3D_Spatial).isDepthWrite());
            String newValue = ((B3D_ParticleEffect) b3D_Spatial).getTextureName();
            StringTokenizer tokenizer = new StringTokenizer(newValue, " ");
            while (tokenizer.hasMoreTokens())
            {
                String nextToken = tokenizer.nextToken();
                if (!nextToken.contains("."))
                {
                    newValue = newValue.replaceAll(nextToken, "");
                }
                newValue = newValue.replaceAll(" ", "");
            }
            particleEmitter.getMaterial().setTexture("Texture", Wizard.getAssetManager().loadTexture(newValue));
            spatial = particleEmitter;
        } else if (b3D_Spatial instanceof B3D_MultipleTextureSkyBox)
        {
            spatial = convertMutlipleTextureSkyBox((B3D_MultipleTextureSkyBox) b3D_Spatial);
            spatial.setUserData("north", ((B3D_MultipleTextureSkyBox) b3D_Spatial).getNorthTextureName());
            spatial.setUserData("south", ((B3D_MultipleTextureSkyBox) b3D_Spatial).getSoutTextureName());
            spatial.setUserData("west", ((B3D_MultipleTextureSkyBox) b3D_Spatial).getWestTextureName());
            spatial.setUserData("east", ((B3D_MultipleTextureSkyBox) b3D_Spatial).getEastTextureName());
            spatial.setUserData("top", ((B3D_MultipleTextureSkyBox) b3D_Spatial).getTopTextureName());
            spatial.setUserData("bottom", ((B3D_MultipleTextureSkyBox) b3D_Spatial).getBottomTextureName());
        } else if (b3D_Spatial instanceof B3D_SingleTextureSkyBox)
        {
            spatial = convertSingleTextureSkyBox((B3D_SingleTextureSkyBox) b3D_Spatial);
            spatial.setUserData("north", ((B3D_SingleTextureSkyBox) b3D_Spatial).getNorthTextureName());
        } else if (b3D_Spatial instanceof B3D_Sphere)
        {
            spatial = convertSphere((B3D_Sphere) b3D_Spatial);
        } else if (b3D_Spatial instanceof B3D_Torus)
        {
            spatial = convertTorus((B3D_Torus) b3D_Spatial);
        }
        if (b3D_Spatial.getParentID() != null)
        {
            spatial.setUserData("parentID", b3D_Spatial.getParentID().toString());
        }
        spatial.setLocalTranslation(b3D_Spatial.getTranslation());
        spatial.setLocalScale(b3D_Spatial.getScale());
        spatial.setLocalRotation(b3D_Spatial.getRotation());
        spatial.setUserData("angles", b3D_Spatial.getAngles());
        spatial.setUserData("scale", spatial.getLocalScale());
        switch (b3D_Spatial.getShadowMode())
        {
            case "Cast":
                spatial.setShadowMode(RenderQueue.ShadowMode.Cast);
                break;
            case "Recieve":
                spatial.setShadowMode(RenderQueue.ShadowMode.Receive);
                break;
            case "Cast&Recieve":
                spatial.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
                break;
            case "Inherit":
                spatial.setShadowMode(RenderQueue.ShadowMode.Inherit);
                break;
            default:
                spatial.setShadowMode(RenderQueue.ShadowMode.Off);
                break;
        }
        if (b3D_Spatial.getPhysics() != null)
        {
            rigidBodyControl = convertPhysics(b3D_Spatial.getPhysics(), spatial);
            spatial.addControl(rigidBodyControl);
        }
        return spatial;
    }

    public static Node convertNode(B3D_Node b3D_Node)
    {
        Node node = new Node(b3D_Node.getName());
        for (B3D_Spatial b3D_Spatial : b3D_Node.getChildren())
        {
            node.attachChild(convertSpatial(b3D_Spatial));
        }
        return node;
    }

    public static Spatial convertBox(B3D_Box b3D_Box)
    {
        Geometry geometry = new Geometry(b3D_Box.getName(), new MBox(1, 1, 1, b3D_Box.getxSlices(), b3D_Box.getySlices(), b3D_Box.getzSlices()));
        geometry.setMaterial(convertMaterial(b3D_Box.getMaterial()));
        return geometry;
    }

    public static Spatial convertModel(B3D_Model b3D_Model)
    {
        Spatial spatial = Wizard.getAssetManager().loadModel(b3D_Model.getPath());
        spatial.setUserData("modelName", b3D_Model.getPath());
        spatial.setMaterial(convertMaterial(b3D_Model.getMaterial()));
        return spatial;
    }

    public static Spatial convertCylinder(B3D_Cylinder b3D_Cylinder)
    {
        Geometry geometry = new Geometry(b3D_Cylinder.getName(), new Cylinder(
                b3D_Cylinder.getAxisSamples(),
                b3D_Cylinder.getRadialSamples(),
                b3D_Cylinder.getRadius(),
                b3D_Cylinder.getRadius2(),
                b3D_Cylinder.getHeight(),
                b3D_Cylinder.isIsClosed(),
                b3D_Cylinder.isIsInverted()));
        geometry.setMaterial(convertMaterial(b3D_Cylinder.getMaterial()));
        return geometry;
    }

    public static ParticleEmitter convertParticleEmitter(B3D_ParticleEffect b3D_ParticleEffect)
    {
        ParticleEmitter particleEmitter = null;
        if (b3D_ParticleEffect.getType().equals(B3D_ParticleEffect.Type.Point))
        {
            particleEmitter = new ParticleEmitter(b3D_ParticleEffect.getName(), ParticleMesh.Type.Point, b3D_ParticleEffect.getMaxParticles());
        } else
        {
            particleEmitter = new ParticleEmitter(b3D_ParticleEffect.getName(), ParticleMesh.Type.Triangle, b3D_ParticleEffect.getMaxParticles());
        }
        particleEmitter.setEndColor(b3D_ParticleEffect.getEndColor());
        particleEmitter.setEndSize(b3D_ParticleEffect.getEndSize());
        particleEmitter.setGravity(b3D_ParticleEffect.getGravity());
        particleEmitter.setHighLife(b3D_ParticleEffect.getHighLife());
        particleEmitter.setImagesX(b3D_ParticleEffect.getImgX());
        particleEmitter.setImagesY(b3D_ParticleEffect.getImgY());
        particleEmitter.setLowLife(b3D_ParticleEffect.getLowLife());
        particleEmitter.setParticlesPerSec(b3D_ParticleEffect.getParticlesPerSecond());
        particleEmitter.setRotateSpeed(b3D_ParticleEffect.getRotateSpeed());
        particleEmitter.setStartColor(b3D_ParticleEffect.getStartColor());
        particleEmitter.setStartSize(b3D_ParticleEffect.getStartSize());
        particleEmitter.getParticleInfluencer().setInitialVelocity(b3D_ParticleEffect.getDirectionVelocity());
        particleEmitter.getParticleInfluencer().setVelocityVariation(b3D_ParticleEffect.getDirectionVariation());
        return particleEmitter;
    }

    public static Spatial convertMutlipleTextureSkyBox(B3D_MultipleTextureSkyBox b3D_MSkyBox)
    {
        return SkyFactory.createSky(
                Wizard.getAssetManager(),
                Wizard.getAssetManager().loadTexture(b3D_MSkyBox.getWestTextureName()),
                Wizard.getAssetManager().loadTexture(b3D_MSkyBox.getEastTextureName()),
                Wizard.getAssetManager().loadTexture(b3D_MSkyBox.getNorthTextureName()),
                Wizard.getAssetManager().loadTexture(b3D_MSkyBox.getSoutTextureName()),
                Wizard.getAssetManager().loadTexture(b3D_MSkyBox.getTopTextureName()),
                Wizard.getAssetManager().loadTexture(b3D_MSkyBox.getBottomTextureName()));
    }

    public static Spatial convertSingleTextureSkyBox(B3D_SingleTextureSkyBox b3D_SSkyBox)
    {
        return SkyFactory.createSky(Wizard.getAssetManager(), Wizard.getAssetManager().loadTexture(b3D_SSkyBox.getNorthTextureName()), true);
    }

    public static Spatial convertSphere(B3D_Sphere b3D_Sphere)
    {
        Geometry geometry = new Geometry(b3D_Sphere.getName(), new Sphere(b3D_Sphere.getzSamples(), b3D_Sphere.getRadialSamples(), b3D_Sphere.getRadius()));
        geometry.setMaterial(convertMaterial(b3D_Sphere.getMaterial()));
        return geometry;
    }

    public static Spatial convertTorus(B3D_Torus b3D_Torus)
    {
        Geometry geometry = new Geometry(b3D_Torus.getName(), new Torus(
                b3D_Torus.getCircleSamples(),
                b3D_Torus.getRadialSamples(),
                b3D_Torus.getInnerRadius(),
                b3D_Torus.getOuterRadius()));
        geometry.setMaterial(convertMaterial(b3D_Torus.getMaterial()));
        return geometry;
    }

    public static Material convertMaterial(B3D_Material b3D_Material)
    {
        Material material = new Material(Wizard.getAssetManager(), b3D_Material.getDefName());
        for (Map.Entry<String, B3D_MaterialPropertyList.Property> entry : b3D_Material.getPropertyList().getProperties().entrySet())
        {
            if (entry.getValue().getPropertyType().toLowerCase().equals("boolean"))
            {
                material.setBoolean(entry.getKey(), Boolean.parseBoolean(entry.getValue().getPropertyValue()));
            } else if (entry.getValue().getPropertyType().toLowerCase().equals("color"))
            {
                StringTokenizer tokenizer = new StringTokenizer(entry.getValue().getPropertyValue(), " ");
                int floatNmbr = 0;
                ColorRGBA newValue = new ColorRGBA();
                while (tokenizer.hasMoreTokens())
                {
                    String nextToken = tokenizer.nextToken();
                    if (floatNmbr == 0)
                    {
                        newValue.r = Float.parseFloat(nextToken);
                    } else if (floatNmbr == 1)
                    {
                        newValue.g = Float.parseFloat(nextToken);
                    } else if (floatNmbr == 2)
                    {
                        newValue.b = Float.parseFloat(nextToken);
                    } else if (floatNmbr == 3)
                    {
                        newValue.a = Float.parseFloat(nextToken);
                    }
                    floatNmbr++;
                }
                material.setColor(entry.getKey(), newValue);
            } else if (entry.getValue().getPropertyType().toLowerCase().equals("texture"))
            {
                material.setTexture(entry.getKey(), Wizard.getAssetManager().loadTexture(entry.getValue().getPropertyValue()));
            } else if (entry.getValue().getPropertyType().toLowerCase().equals("float"))
            {
                material.setFloat(entry.getKey(), Float.parseFloat(entry.getValue().getPropertyValue()));
            } else if (entry.getValue().getPropertyType().toLowerCase().equals("int"))
            {
                material.setInt(entry.getKey(), Integer.parseInt(entry.getValue().getPropertyValue()));
            } else if (entry.getValue().getPropertyType().toLowerCase().equals("vector2"))
            {
                StringTokenizer tokenizer = new StringTokenizer(entry.getValue().getPropertyValue().substring(1, entry.getValue().getPropertyValue().length() - 1), " ");
                material.setVector2(entry.getKey(), new Vector2f(
                        Float.parseFloat(tokenizer.nextToken()),
                        Float.parseFloat(tokenizer.nextToken())));

            } else if (entry.getValue().getPropertyType().toLowerCase().equals("vector3"))
            {
                StringTokenizer tokenizer = new StringTokenizer(entry.getValue().getPropertyValue().substring(1, entry.getValue().getPropertyValue().length() - 1), " ");
                material.setVector3(entry.getKey(), new Vector3f(
                        Float.parseFloat(tokenizer.nextToken()),
                        Float.parseFloat(tokenizer.nextToken()),
                        Float.parseFloat(tokenizer.nextToken())));
            } else if (entry.getValue().getPropertyType().toLowerCase().equals("vector4"))
            {
                StringTokenizer tokenizer = new StringTokenizer(entry.getValue().getPropertyValue().substring(1, entry.getValue().getPropertyValue().length() - 1), " ");
                material.setVector4(entry.getKey(), new Vector4f(
                        Float.parseFloat(tokenizer.nextToken()),
                        Float.parseFloat(tokenizer.nextToken()),
                        Float.parseFloat(tokenizer.nextToken()),
                        Float.parseFloat(tokenizer.nextToken())));
            }
        }
        return material;
    }

    public static RigidBodyControl convertPhysics(B3D_Physics b3D_Physics, Spatial spatial)
    {
        RigidBodyControl rigidBodyControl = new RigidBodyControl();
        rigidBodyControl.setCollisionShape(convertCollisionShape(b3D_Physics.getcShape(), spatial));
        rigidBodyControl.setMass(b3D_Physics.getMass());
        rigidBodyControl.setRestitution(b3D_Physics.getResitution());
        rigidBodyControl.setKinematic(b3D_Physics.isKinematic());
        return rigidBodyControl;
    }

    public static CollisionShape convertCollisionShape(B3D_CShape b3D_CShape, Spatial spatial)
    {
        CollisionShape collisionShape = null;
        if (b3D_CShape instanceof B3D_BoxShape)
        {
            collisionShape = new BoxCollisionShape(((B3D_BoxShape) b3D_CShape).getHalfExtends());
        } else if (b3D_CShape instanceof B3D_CapsuleShape)
        {
            collisionShape = new CapsuleCollisionShape(((B3D_CapsuleShape) b3D_CShape).getRadius(), ((B3D_CapsuleShape) b3D_CShape).getHeight());
        } else if (b3D_CShape instanceof B3D_ConeShape)
        {
            collisionShape = new ConeCollisionShape(((B3D_ConeShape) b3D_CShape).getRadius(), ((B3D_ConeShape) b3D_CShape).getHeight());
        } else if (b3D_CShape instanceof B3D_CylinderShape)
        {
            collisionShape = new CylinderCollisionShape(((B3D_CylinderShape) b3D_CShape).getHalfExtends());
        } else if (b3D_CShape instanceof B3D_DynamicMeshShape)
        {
            collisionShape = CollisionShapeFactory.createDynamicMeshShape(spatial);
            spatial.setUserData("cShape", "dynamic");
        } else if (b3D_CShape instanceof B3D_StaticMeshShape)
        {
            collisionShape = CollisionShapeFactory.createDynamicMeshShape(spatial);
            spatial.setUserData("cShape", "static");
        }
        return collisionShape;
    }

    public static MotionEvent convertMotionEvent(B3D_MotionEvent b3D_MotionEvent)
    {
        MotionPath motionPath = new MotionPath();
        Spatial spatial;
        if (b3D_MotionEvent.getObject().equals(B3D_MotionEvent.Cam.CAM))
        {
            spatial = Wizard.getCameraNode();
        } else
        {
            spatial = (Spatial) Wizard.getElementList().getObject((UUID) b3D_MotionEvent.getObject());
        }
        for (Vector3f vec3 : b3D_MotionEvent.getMotionPath().getWayPoints())
        {
            motionPath.addWayPoint(vec3);
        }
        motionPath.setCurveTension(b3D_MotionEvent.getMotionPath().getCurveTension());
        motionPath.setCycle(b3D_MotionEvent.getMotionPath().isCycle());
        LoopMode loopMode;
        if (b3D_MotionEvent.getMotionPath().getLoopMode().equals(B3D_MotionPath.LoopMode.Cycle))
        {
            loopMode = LoopMode.Cycle;
        } else if (b3D_MotionEvent.getMotionPath().getLoopMode().equals(B3D_MotionPath.LoopMode.DontLoop))
        {
            loopMode = LoopMode.DontLoop;
        } else
        {
            loopMode = LoopMode.Loop;
        }
        MotionEvent motionEvent = new MotionEvent(spatial, motionPath, loopMode);
        motionEvent.setSpeed(b3D_MotionEvent.getMotionPath().getSpeed());
        if (b3D_MotionEvent.getMotionPath().getDirectionType().equals(B3D_MotionPath.DirectionType.LookAt))
        {
            motionEvent.setDirectionType(MotionEvent.Direction.LookAt);
        } else if (b3D_MotionEvent.getMotionPath().getDirectionType().equals(B3D_MotionPath.DirectionType.None))
        {
            motionEvent.setDirectionType(MotionEvent.Direction.None);
        } else if (b3D_MotionEvent.getMotionPath().getDirectionType().equals(B3D_MotionPath.DirectionType.Path))
        {
            motionEvent.setDirectionType(MotionEvent.Direction.Path);
        } else if (b3D_MotionEvent.getMotionPath().getDirectionType().equals(B3D_MotionPath.DirectionType.PathAndRotation))
        {
            motionEvent.setDirectionType(MotionEvent.Direction.PathAndRotation);
        } else
        {
            motionEvent.setDirectionType(MotionEvent.Direction.Rotation);
        }
        if (b3D_MotionEvent.getMotionPath().getRotation() != null)
        {
            motionEvent.setRotation(b3D_MotionEvent.getMotionPath().getRotation());
        }
        if (b3D_MotionEvent.getMotionPath().getLookAtObject() != null)
        {
            if (b3D_MotionEvent.getMotionPath().getLookAtObject().equals(B3D_MotionEvent.Cam.CAM))
            {
                motionEvent.setLookAt(Wizard.getCameraNode().getWorldTranslation(), Vector3f.UNIT_Y);
            } else
            {
                UUID id = (UUID) b3D_MotionEvent.getMotionPath().getLookAtObject();
                motionEvent.setLookAt(((Spatial) Wizard.getElementList().getObject(id)).getWorldTranslation(), Vector3f.UNIT_Y);
            }
        }
        motionPath.setPathSplineType(Spline.SplineType.CatmullRom);
        return motionEvent;
    }
}
